<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="layui/css/layui.css"  media="all">
</head>
<body>
	<form class="layui-form">
		<div class="layui-form-item">
			<label class="layui-form-label"><span style="color: red;">*</span>
				用户名</label>
			<div class="layui-input-inline">
				<input type="text" name="name" id="name" required lay-verify="required"
					placeholder="请输入" autocomplete="off" class="layui-input">
			</div>
		</div>
		
		<div class="layui-form-item">
			<label class="layui-form-label"><span style="color: red;">*</span>
				密码</label>
			<div class="layui-input-inline">
				<input type="text" name="password" id="password" required lay-verify="required"
					placeholder="请输入" autocomplete="off" class="layui-input">
			</div>
		</div>
	

		<!--
		<div class="layui-form-item">
			<label class="layui-form-label"><span style="color: red;">*</span>
			账户创立时间</label>
			<div class="layui-input-inline">
				<input type="text" name="CreateTime" id="CreateTime" required lay-verify="required"
					placeholder="请输入" autocomplete="off" class="layui-input">
			</div>
		</div>
		-->
		
		<div class="layui-form-item">
			<label class="layui-form-label"><span style="color: red;">*</span>
			手机号</label>
			<div class="layui-input-inline">
				<input type="text" name="phone" id="phone" required lay-verify="required"
					placeholder="请输入" autocomplete="off" class="layui-input">
			</div>
		</div>
		
		<!--<div class="layui-form-item">
			<label class="layui-form-label"><span style="color: red;">*</span>
			创建时间</label>
			<div class="layui-input-inline">
				<input type="text" name="createTime" id="createTime" required lay-verify="required"
					placeholder="请输入" autocomplete="off" class="layui-input">
			</div>
		</div>-->
		
	<!--	<div class="layui-form-item">
			<label class="layui-form-label"><span style="color: red;">*</span>
			所属角色</label>
		<!--	<div class="layui-input-inline">
				<input type="text" name="roleId" id="roleId" required lay-verify="required"
					placeholder="请输入" autocomplete="off" class="layui-input">
			</div>-->
			
			
				<!--<label class="layui-form-label">类型</label>-->
				<!--<div class="layui-input-inline">
					<select name="roleId" id="roleId">

						<option value="">请选择</option>

					</select>
				</div>
				-->
		</div>-->
		<div class="layui-form-item">
			<label class="layui-form-label"><span style="color: red;">*</span>
		状态</label>
			<div class="layui-input-inline">
				<input type="text" name="enable" id="enable" required lay-verify="required"
					placeholder="请输入" autocomplete="off" class="layui-input">
			</div>
		</div>
		
		
	
		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="formDemo">立即添加</button>
			</div>
		</div>
	</form>
</body>
<script src="js/User.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript" src="layui/layui.js"></script>
	<script>
		layui.use(['form','upload'], function() {
			var form = layui.form;
			var upload=layui.upload;
			var $ = layui.jquery; 
			/*
			 
			 * */
				/*下拉选择*/
			/*function intype() {
					$.post(globalData.server + 'user/UserType', {}, function(data) {
						var list = data.data;
						var select = document.getElementById('roleId'); //获取下拉框的id

						if(list != null || list.size() > 1) {
							for(var c in list) {
								var option = document.createElement("option");
								option.setAttribute("value", list[c].roleId);
								option.innerText = list[c].rname;
								select.appendChild(option);
							}
							form.render("select");
						};

					}, "json");
				}
				intype();*/ ///回调
			//监听提交
			
			/*
			 
			 * form.on('submit(forDemo)', function(data) {
					var d = data.field;
					console.log(d);
					console.log(d.protectEMail);
					var url = globalData.server + 'public/adduser';
					
					if(!pas.test(d.password)){
						layer.msg('密码必须6到12位，且不能出现空格', {
							icon: 5
						});
						return false;
					}else  {
						$.post(url, d, function(data) {
							if(data.count > 0) {
								console.log('添加成功');
								var index = parent.layer.getFrameIndex(window.name);
								parent.layer.close(index);
							} else {
								layer.alert("添加失败，用户名重复", {
									icon: 2,
									closeBtn: 0,
									title: "添加失败"
								});
							}
						}, "json");
					}

					return false;
				});
			 * */
			
				form.on('submit(formDemo)', function(data) {
					var d = data.field;
					var url=globalData.server+ 'user/addUser';
					$.post(url, d, function(data) {
						if(data.count > 0) {
							alert("添加成功")
							var index = parent.layer.getFrameIndex(window.name);
							parent.layer.close(index);
						}else {
								layer.alert("添加失败，用户名重复", {
									icon: 2,
									closeBtn: 0,
									title: "添加失败"
								});
							}
						
					
						
					},"json")
					return false;
				});
		});
	</script>
</html>